<?php

Class UrlBridge{
	private $homefolder_regex;
	private $homeindex;
	private $distance;
	
	function __construct($homefolder){
		$this->homefolder_regex = $homefolder;
		$currentFolder = explode(DIRECTORY_SEPARATOR, getcwd());
		$this->homeindex = $this->getIndex($homefolder, $currentFolder);
		$this->distance = count($currentFolder) - $this->homeindex - 1;
	}
	
	function getIndex($search_regex, $search_array){
		$i = 0;
		$limit = count($search_array);
		
		while($i < $limit){
			if(preg_match($search_regex, $search_array[$i]) == 1){
				return $i;
			}
			
			$i++;
		}
		
		return -1;
	}
	
	function getDistance(){
		return $this->distance;
	}
	
	function getDots(){
		$i = 0;
		$limit = $this->distance;
		$dots = "";

		while($i < $limit){
			$dots .= "../";
			$i++;
		}

		return $dots;
	}
}

?>